<template>
  <div>
    <h2>我是孙组件</h2>
    <p>title:{{ title }}</p>
    <p>age:{{ $attrs.age }}</p>
    <button @click="handClick">改变age</button>
  </div>
</template>

<!-- <script>
export default {
  name: 'Child2',
  props: ['title'],
  methods: {
    handClick() {
      this.$emit('changAge', this.$attrs.age + 1)
      // this.$attrs.onChangAge(this.$attrs.age + 1)
    }
  },
  mounted() {
    console.log('孙组件$attrs:', this.$attrs)
  }
}
</script> -->

<script setup>
import { onMounted, useAttrs } from 'vue'

defineOptions({
  name: 'Child2'
})
defineProps({
  title: String
})
const attrs = useAttrs()
const emit = defineEmits(['changAge'])
const handClick = () => {
  emit('changAge', attrs.age + 1)
  //  attrs.onChangAge(attrs.age + 1)
}
onMounted(() => {
  console.log('孙组件$attrs:', attrs)
})
</script>
